package com.wlr.study.leetcode;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Deque;
import java.util.LinkedList;
import java.util.List;

/**
 * @author lerong.wang
 * @version 1.0.0
 * @description
 * @date 2024/12/25 11:30
 */
public class LeetCode515 {
    public List<Integer> largestValues(TreeNode root) {
        List<Integer> result = new ArrayList<>();
        Deque<TreeNode> que = new LinkedList<>();
        if(root == null) return result;
        que.offer(root);
        int i = 0;
        while(!que.isEmpty()){
            int size = que.size();
            int last = Integer.MIN_VALUE;
            while(size>0){
                TreeNode temp = que.poll();
                int curr = temp.val;
                int max = compareVal(last, curr);
                last = curr;
                if(result.size()==i){
                    result.add(max);
                }else{
                    result.set(i,max);
                }
                if(temp.left!=null) que.offer(temp.left);
                if(temp.right!=null) que.offer(temp.right);
                size--;
            }
            i++;
        }
        return result;
    }
    public int compareVal(int last, int curr){
        return Math.max(last, curr);
    }


    public static void main(String[] args) {
//        LeetCode515 leetCode515 = new LeetCode515();
//        TreeNode root = new TreeNode(1);
//        root.left = new TreeNode(3);
//        root.right = new TreeNode(2);
//        root.left.left = new TreeNode(5);
//        root.left.right = new TreeNode(3);
//        root.right.right = new TreeNode(9);
//        List<Integer> integers = leetCode515.largestValues(root);
//        integers.forEach(System.out::println);

        ArrayList<Integer> objects = new ArrayList<>();
        for (int i = 0; i < 70; i++) {
            objects.add(i);
        }
        try {
            Field elementData = ArrayList.class.getDeclaredField("elementData");
            elementData.setAccessible(true);
            System.out.println(((Object[] )elementData.get(objects)).length);
        } catch (NoSuchFieldException e) {
            throw new RuntimeException(e);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        }

        System.out.println(objects.size());

    }

}